package com.luxk.db.errorcode;

public enum ErrorCodeStorage implements ErrorCode {
	
	ERROR_CREATE_FILE(0,
			"Fail to create file {0}",
			"Not permitted or insufficient space or already exists",
			"Check permission or space"),

	ERROR_OPEN_FILE(1,
			"Fail to open file {0}",
			"Not permitted or not exists",
			"Check permission or existance"),

	ERROR_CLOSE_FILE(2,
			"Fail to close file {0}",
			"Not permitted or not exists",
			"Check permission or existance"),
					
	ERROR_FILE_ALREADY_OPEN(3,
			"File {0} already open",
			"Try to open file already opened",
			"Check operation"),

	ERROR_INVALID_FILE_SIZE(4,
			"File {0} size is invalid {1}",
			"File size mismatched",
			"Check file status"),
	
	ERROR_READ_FILE(5,
			"Fail to read file {0}, offset: {1}, size: {2}",
			"Not permitted or not exists",
			"Check permission or existance"),

	ERROR_WRITE_FILE(5,
			"Fail to write file {0}, offset: {1}, size: {2}",
			"Not permitted or insufficient space",
			"Check permission or space"),

	ERROR_INVALID_PATH(6,
			"Invalid path {0}",
			"File or directory not exists",
			"Check path string and retry"),

	ERROR_NOT_DIRECTORY(7,
			"Given path {0} is not directory",
			"Path is not cirectory",
			"Check path string and retry"),

	ERROR_CREATE_DIRECTORY(8,
			"Fail to create directory {0}",
			"Not permitted or path already exists",
			"Check permission or existance"),

	ERROR_DELETE(9,
			"Fail to delete file or directory {0}",
			"Not permitted or already deleted",
			"Check permission or existance")
	;

	private final int codeOffset = 20000;
	private final int code;
	private final String desc;
	private final String cause;
	private final String action;
	
	private ErrorCodeStorage(int id, String desc, String cause, String action) {
		this.code = this.codeOffset + id;
		this.desc = desc;
		this.cause = cause;
		this.action = action;
	}

	public int getCode() { return this.code; }
	public String getDesc() { return this.desc; }
	public String getCause() { return this.cause; }
	public String getAction() { return this.action; }
	public String toString() {
		return String.format("ERROR-%05d %s", this.code, this.desc);
	}
}
